/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.bld.util.conexao;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Pedro
 */
public class ConexaoPGSQL {

    private static final Properties props = new Properties();
    private static final Logger logger = Logger.getLogger(ConexaoPGSQL.class.getName());

    static {

        try {
            
            Class.forName("org.postgresql.Driver");
            //FileInputStream file = new FileInputStream("./src/java/bld.properties");
            InputStream file = ConexaoPGSQL.class.getResourceAsStream("bld.properties");
            props.load(file);
        } catch (ClassNotFoundException | IOException ex) {
            logger.log(Level.SEVERE, ex.toString(), ex);
        }
    }

    public static Connection getConection() throws SQLException {

        Connection conn = DriverManager.getConnection(props.getProperty("host"), props.getProperty("username"), props.getProperty("password"));

        conn.setAutoCommit(false);

        return conn;
    }
    
    
    public static void main(String[] args) throws SQLException {
        getConection();
    }
}
